﻿$(document).ready(function () {
    //Lay danh sach quan huyen
    xGetQuanHuyen($('.ddlTinhThanh_Search').val(), 1);
    //
    $('.ddlTinhThanh_Search').change(function () {
        xGetQuanHuyen($(this).val(), 1);
    });

    $('#btn-Search-Quick').click(function () {
        strTinhThanh = $('.ddlTinhThanh_Search').val();
        strQuanHuyen = $('.ddlQuanHuyen_Search').val();
        strChuyenMuc = $('.ddlChuyenMuc_Search').val();
        strGiaPhong = $('.ddlGiaPhong_Search').val();
        strDienTich = $('.ddlDienTich_Search').val();
        //
        strKhuVuc = strQuanHuyen;
        if (strTinhThanh == 'toan-quoc') strKhuVuc = strTinhThanh;
        if (strKhuVuc == '0') strKhuVuc = $('.ddlTinhThanh_Search').find("option:selected").attr('ten-ko-dau'); ;
        //
        strURL = "/" + strChuyenMuc + "/" + strKhuVuc + "/" + strGiaPhong + "/" + strDienTich + "/1";
        //
        //alert(strURL);
        window.location.href = strURL;
    });
});
//LOAD DANH SÁCH KHU VỰC
function xGetQuanHuyen(kvparent_id, type) {
    //$("#loader").show(); 
    $.ajax({
        type: "POST",
        url: "/Default.aspx/fncGetDropKhuVuc_By_ParentID",
        data: '{strParentID: "' + kvparent_id + '", iType:1}',
        contentType: "application/json; charset=utf-8",
        dataType: "json",
        success: function (response) {
            var Data = response.d;
            if (type == 0) $('.ddlTinhThanh_Search').html(Data);
            else $('.ddlQuanHuyen_Search').html(Data);
            xSetQuanHuyen();
        },
        failure: function (response) {
            //alert("failure: " + response.d);
        },
        error: function (response) {
            //alert("error: " + response.d);
        }
    });
}

//Set value cho danh sach quan huyen neu da chon value
function xSetQuanHuyen() {
    if ($('.hdQuanHuyen_Search').val() != "") {
        $(".ddlQuanHuyen_Search option").each(function () {
            if ($(this).attr('value') == $('.hdQuanHuyen_Search').val()) {
                $(this).prop('selected', true);
            }
        });
    }
}